/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ticketmaster.presentation.controls;

import java.awt.Component;
import javax.swing.JCheckBox;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author Wei Liu
 */
public class CheckCellRenderer extends JCheckBox implements TableCellRenderer
{

    protected static Border noFocusBorder;

    public CheckCellRenderer()
    {
        super();
        noFocusBorder = new EmptyBorder(1, 2, 1, 2);
        setOpaque(true);
        setBorder(noFocusBorder);
        this.setHorizontalAlignment(CheckCellRenderer.CENTER);
    }

    public Component getTableCellRendererComponent(JTable table,
                                                   Object value, boolean isSelected, boolean hasFocus,
                                                   int row, int column)
    {
        if (value instanceof Boolean)
        {
            Boolean b = (Boolean) value;
            setSelected(b.booleanValue());
        }

        setBackground(isSelected && !hasFocus
                      ? table.getSelectionBackground() : table.getBackground());
//        setBackground(isSelected
//                      ? Color.LIGHT_GRAY : table.getBackground());
        setForeground(isSelected && !hasFocus
                      ? table.getSelectionForeground() : table.getForeground());

        setFont(table.getFont());
        setBorder(hasFocus ? UIManager.getBorder(
                "Table.focusCellHighlightBorder") : noFocusBorder);

        return this;
    }
}
